package com.rd.emf.geneditor;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.osgi.framework.BundleContext;

import com.rd.emf.geneditor.view.ImageRegistry;

public class EMFGenericEditorPlugin extends AbstractUIPlugin {

	public static final String PLUGIN_ID = "com.criticalsoftware.emf.genericeditor";
	// The shared instance
	private static EMFGenericEditorPlugin plugin;

	public EMFGenericEditorPlugin() {
		super();
	}

	@Override
	public void start(BundleContext context) throws Exception {
		super.start(context);
		plugin = this;
		
		
	}
	
	
	@Override
	public void stop(BundleContext context) throws Exception {
		plugin = null;
		if (getPreferenceStore().needsSaving())
			((ScopedPreferenceStore) getPreferenceStore()).save();
		ImageRegistry.getDefault().dispose();
		super.stop(context);

	}
	/**
	 * Returns the shared instance
	 * 
	 * @return the shared instance
	 */
	public static EMFGenericEditorPlugin getDefault() {
		return plugin;
	}

	/**
	 * Returns an image descriptor for the image file at the given plug-in
	 * relative path !Note, that you have to take care of disposing any images
	 * created by createImage()!
	 * 
	 * @param path
	 *            the path
	 * @return the image descriptor
	 */
	public static ImageDescriptor getImageDescriptor(String path) {
		return imageDescriptorFromPlugin(PLUGIN_ID, path);
	}

	public static void logError(String string, Exception e) {
		getDefault().getLog().log(
				new Status(IStatus.ERROR, PLUGIN_ID, string, e));
	}

	public static void logError(String string) {
		getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, string));
	}
}
